<div class="app flex-row align-items-center">
  <div class="container">
    <div class="row justify-content-center">
      <div class="col-md-6">
        <div class="card mx-4">

          <form name="form" role="form" (ngSubmit)="register()" #registerForm="ngForm" *ngIf="!success">
            <div class="card-body p-4">
              <h1>注册</h1>
              <p class="text-muted">创建账户</p>

              <div class="alert alert-success" *ngIf="success">
                  <strong>Registration saved!</strong> Please check your email for confirmation.
              </div>
              <div class="alert alert-danger" *ngIf="error">
                  <strong>Registration failed!</strong> Please try again later.
              </div>
              <div class="alert alert-danger" *ngIf="errorUserExists">
                  <strong>Login name already registered!</strong> Please choose another one.
              </div>
              <div class="alert alert-danger" *ngIf="errorEmailExists">
                  <strong>Email is already in use!</strong> Please choose another one.
              </div>
              <div class="alert alert-danger" *ngIf="doNotMatch">
                  The password and its confirmation do not match!
              </div>


              <div class="input-group mb-3">
                <div class="input-group-prepend">
                  <span class="input-group-text"><i class="icon-user"></i></span>
                </div>
                <input type="text" class="form-control" [(ngModel)]="registerAccount.login" name="login" id="login" #login="ngModel"
                      placeholder="用户名" required minlength="1" maxlength="50" pattern="^[_.@A-Za-z0-9-]*$">
                <div *ngIf="login.dirty && login.invalid">
                    <small class="form-text text-danger" *ngIf="login.errors.required">
                        Your username is required.
                    </small>
                    <small class="form-text text-danger" *ngIf="login.errors.minlength"
                           >
                        Your username is required to be at least 1 character.
                    </small>
                    <small class="form-text text-danger" *ngIf="login.errors.maxlength"
                           >
                        Your username cannot be longer than 50 characters.
                    </small>
                    <small class="form-text text-danger" *ngIf="login.errors.pattern"
                          >
                        Your username can only contain letters and digits.
                    </small>
                </div>
              </div>

              <div class="input-group mb-3">
                <div class="input-group-prepend">
                  <span class="input-group-text">@</span>
                </div>
                <input type="text" class="form-control" name="email" #email="ngModel" placeholder="Your email"
                      [(ngModel)]="registerAccount.email" minlength=5 maxlength=254 email required>
                <div *ngIf="email.dirty && email.invalid">
                    <small class="form-text text-danger" *ngIf="email.errors.required"
                           >
                        Your email is required.
                    </small>
                    <small class="form-text text-danger" *ngIf="email.errors.invalid"
                          >
                        Your email is invalid.
                    </small>
                    <small class="form-text text-danger" *ngIf="email.errors.minlength"
                          >
                        Your email is required to be at least 5 characters.
                    </small>
                    <small class="form-text text-danger" *ngIf="email.errors.maxlength"
                          >
                        Your email cannot be longer than 100 characters.
                    </small>
                </div>
              </div>

              <div class="input-group mb-3">
                <div class="input-group-prepend">
                  <span class="input-group-text"><i class="icon-lock"></i></span>
                </div>
                <input type="password" class="form-control" name="password" #password="ngModel" placeholder="New password"
                      [(ngModel)]="registerAccount.password" minlength=4 maxlength=50 required>
                <div *ngIf="password.dirty && password.invalid">
                    <small class="form-text text-danger" *ngIf="password.errors.required"
                            >
                        Your password is required.
                    </small>
                    <small class="form-text text-danger" *ngIf="password.errors.minlength"
                            >
                        Your password is required to be at least 4 characters.
                    </small>
                    <small class="form-text text-danger" *ngIf="password.errors.maxlength"
                            >
                        Your password cannot be longer than 50 characters.
                    </small>
                </div>
              </div>
              <div class="input-group mb-3">
                  <app-password-strength-bar [passwordToCheck]="registerAccount.password"></app-password-strength-bar>
              </div>

              <div class="input-group mb-4">
                <div class="input-group-prepend">
                  <span class="input-group-text"><i class="icon-lock"></i></span>
                </div>
                <input type="password" class="form-control" name="confirmPassword" #confirmPasswordInput="ngModel" placeholder="Confirm the new password"
                      [(ngModel)]="confirmPassword" minlength=4 maxlength=50 required>
                <div *ngIf="confirmPasswordInput.dirty && confirmPasswordInput.invalid">
                    <small class="form-text text-danger" *ngIf="confirmPasswordInput.errors.required"
                          >
                        Your confirmation password is required.
                    </small>
                    <small class="form-text text-danger" *ngIf="confirmPasswordInput.errors.minlength"
                         >
                        Your confirmation password is required to be at least 4 characters.
                    </small>
                    <small class="form-text text-danger" *ngIf="confirmPasswordInput.errors.maxlength"
                          >
                        Your confirmation password cannot be longer than 50 characters.
                    </small>
                </div>
              </div>
            </div>
            <div class="card-footer p-4">
              <div class="row">
                <div class="col-6">
                  <button type="submit" [disabled]="registerForm.form.invalid" class="btn btn-block btn-primary"><span>创建账户</span></button>
                </div>
                <div class="col-6">
                  <button class="btn btn-block btn-warning" type="button"><span>取消</span></button>
                </div>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>



  </div>
</div>
